﻿<%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeFile="SetSlide.aspx.cs"
    Inherits="Whir_System_Module_Template_SetSlide" %>

<%@ Register Src="~/UserControls/FieldSelect.ascx" TagName="FieldSelect" TagPrefix="cc0" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>幻灯片标签</title>
    <link href="../../Skin/Default/Css/main.css" rel="stylesheet" type="text/css" />

    <script src="../../Js/jquery/jquery1.3.11.pack.js" type="text/javascript"></script>

    <script src="../../Js/JQuery/jquery.tabs.pack.js" type="text/javascript"></script>

    <link rel="stylesheet" href="../../Js/JQuery/tabs/jquery.tabs.css" type="text/css"
        media="print, projection, screen" />
    <style type="text/css">
    html {
	    overflow-x: hidden; /*隐藏水平滚动条*/
    }
    </style>
    <base target="_self" />
</head>
<body onload="setEdit();">
    <form id="form1" runat="server">
        <div id="tabsNav">
            <ul class="tabs-nav">
                <li><a href="#tab1"><span>基本设置</span></a></li>
                <li><a href="#tab2"><span>高级配置</span></a></li>
            </ul>
            <div id="tab1">
                <table width="600px" border="0" cellpadding="0" cellspacing="1" bgcolor="#DADADA">
                    <tr>
                        <td width="110px" height="28" align="center" class="form_tdText">ID </td>
                        <td class="form_td">&nbsp;<asp:TextBox ID="txtID" runat="server" Width="80"></asp:TextBox>
                            <font color="red">*</font> <a onclick="document.getElementById('txtID').value='Info'+(Math.round(Math.random()*100));">
                                随机</a></td>
                    </tr>
                    <tr>
                        <td height="28" align="center" class="form_tdText">宽度 </td>
                        <td class="form_td">&nbsp;<asp:TextBox ID="txtWidth" runat="server" Width="80">190</asp:TextBox>
                            <font color="red">[数字]</font> </td>
                    </tr>
                    <tr>
                        <td height="28" align="center" class="form_tdText">高度 </td>
                        <td class="form_td">&nbsp;<asp:TextBox ID="txtHeight" runat="server" Width="80">210</asp:TextBox>
                            <font color="red">[数字]</font> </td>
                    </tr>
                    <tr>
                        <td height="28" align="center" class="form_tdText">文本高度 </td>
                        <td class="form_td">&nbsp;<asp:TextBox ID="txtTextHeight" runat="server" Width="80">0</asp:TextBox>
                            <font color="red">[0为不显示]</font> </td>
                    </tr>
                    <tr>
                        <td height="28" align="center" class="form_tdText">Js路径 </td>
                        <td class="form_td">&nbsp;<asp:TextBox ID="txtJsUrl" runat="server" Width="200">~/Script/FlashMovie.js</asp:TextBox>
                            <font color="red">[引用js文件的路径]</font> </td>
                    </tr>
                    <tr>
                        <td height="28" align="center" class="form_tdText">数据条数 </td>
                        <td class="form_td">&nbsp;<asp:TextBox ID="txtTop" runat="server" Width="80">4</asp:TextBox>
                            <font color="red">[数字]</font> </td>
                    </tr>
                    <cc0:FieldSelect ID="fs1" runat="server" />
                    <tr>
                        <td height="28" align="center" class="form_tdText" colspan="2">&nbsp;<asp:TextBox
                            ID="txtContent" runat="server" Width="470" Height="160px"></asp:TextBox><br />
                            <font color="red">[格式：'图片地址','链接地址','提示文字']</font> </td>
                    </tr>
                    <tr>
                        <td height="28" align="center" class="form_tdText" colspan="2">
                            <input id="Button1" type="button" value="插入" class="btn_default" onclick="insertLabel();" />
                            <input id="Button2" type="button" value="编辑" class="btn_default" onclick="editLabel();" />
                            <asp:Button ID="btnF" runat="server" OnClick="btnF_Click" />
                        </td>
                    </tr>
                </table>
            </div>
            <div id="tab2">
                <table width="600px" border="0" cellpadding="0" cellspacing="1" bgcolor="#DADADA">
                    <tr>
                        <td height="28" align="center" class="form_tdText">数据条件 </td>
                        <td class="form_td">&nbsp;<asp:TextBox ID="txtWhere" runat="server" Width="150"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td height="28" align="center" class="form_tdText">数据排序 </td>
                        <td class="form_td">&nbsp;<asp:TextBox ID="txtOrder" runat="server" Width="150">CREATEDATE DESC</asp:TextBox>
                        </td>
                    </tr>
                </table>
            </div>
            <asp:HiddenField ID="hfFormID" runat="server" />
            <asp:HiddenField ID="hfSelect" runat="server" />
    </form>
</body>
</html>

<script type="text/javascript">
        $('#tabsNav').tabs(1);
</script>

<script language="javascript">
//编辑时初始化数据
function setEdit()
{
    document.getElementById("btnF").style.display = 'none';
    var isEdit = (window.location.href.indexOf("?e")!=-1) ? true : false;
    if(isEdit)
    {
        document.getElementById("Button1").style.display = 'none';
        document.getElementById("Button2").style.display = '';
    }
    else
    {
        document.getElementById("Button1").style.display = '';
        document.getElementById("Button2").style.display = 'none';
    }
    //判断是否第一次加载
    var ispostback = '<%= isPostBack %>';
    if(ispostback == '1')
        return;
    //end
    
    if(isEdit)
    {
        var label = window.dialogArguments;    //标签
        
        var index1 = label.indexOf(">");
        var index2 = label.lastIndexOf("<");
        
        document.getElementById("txtContent").value = label.substring(index1+3, index2-2);    //内容[注意去掉前后换行符]
        
        var top = label.substring(0, index1+1);    //头部
        
        while(true)
        {
            var mc = top.match(new RegExp("[a-zA-Z]+[ ]*=[ ]*\"[^\"]*\""));    //取参数
            
            if(mc != null)
            {
                var k = mc[0].indexOf('=');
                var m1=mc[0].substring(0,k).toLowerCase(), m2=mc[0].substring(k+2,mc[0].length-1);
                
                switch(m1)
                {
                    case "id":
                        document.getElementById("txtID").value=m2;
                        break;
                    case "class":
                        document.getElementById("txtClass").value=m2;
                        break;
                    case "style":
                        document.getElementById("txtStyle").value=m2;
                        break;
                    case "share":
                        document.getElementById("cbShare").checked=(m2=="true") ? true : false;
                        break;
                    case "top":
                        document.getElementById("txtTop").value=m2;
                        break;
                    case "select":
                        document.getElementById("hfSelect").value = m2;
                        break;
                    case "from":
                        var ddl1 = document.getElementById("fs1_ddlModel");
                        for(var i=0; i<ddl1.options.length; i++)
                        {
                            var v = ddl1.options[i].value;
                            if(v != "-1")
                            {
                                var vs = v.split('|');
                                if(vs[1] == m2)
                                {
                                    ddl1.options[i].selected = true;    //选择功能模块
                                    break;
                                }
                            }
                        }
                        break;
                    case "where":
                        document.getElementById("txtWhere").value=m2.replace("&lt;", "<").replace("&gt;", ">");
                        break;
                    case "order":
                        document.getElementById("txtOrder").value=m2;
                        break;
                    case "formid":
                        document.getElementById("hfFormID").value=m2;
                        break;
                    default:break;
                }
                
                top = top.replace(mc[0], "");    //逐个替换
            }
            else
                break;
        }
        
        document.getElementById("btnF").click();    //绑定表单
    }
}

//保存
function insertLabel()
{
    if(!checkForm())
       return false;

    var MyArgs = window.dialogArguments;

    MyArgs[0] = MyArgs[0] + labelCreate();
    
    window.returnValue = MyArgs;
    window.close();
}

//修改
function editLabel()
{
    if(!checkForm())
       return false;
    
    window.returnValue = labelCreate();
    window.close();
}

function labelCreate()
{
    var Id = document.getElementById("txtID").value;
    var Width = document.getElementById("txtWidth").value;
    var Height = document.getElementById("txtHeight").value;
    var TextHeight = document.getElementById("txtTextHeight").value;
    var JsUrl = document.getElementById("txtJsUrl").value;
    var Top = document.getElementById("txtTop").value;
    
    var From = document.getElementById("fs1$ddlModel").value;    //表名
    var FormID = document.getElementById("fs1$ddlForm").value;    //表单
    //字段
    var cbl=document.all.fs1_cblField;
    var Select="";
    
    for(var i=0;i<cbl.rows.length;i++)   
    {
       for(var j=0; j<3; j++)
       {
           objCheckBox = document.getElementById("fs1_cblField_" + (i*3+j));
           
           if(objCheckBox == null)
               break;
           
           if(objCheckBox.checked)
               Select += cbl.rows[i].cells[j].childNodes(1).innerText + ",";
       }
    }
    
    if(Select != "")
        Select = Select.substring(0, Select.length-1);
    else
        Select = "*";
    //end
    var Where = document.getElementById("txtWhere").value.replace("<", "&lt;").replace(">", "&gt;");
    var Order = document.getElementById("txtOrder").value;
    var Content = document.getElementById("txtContent").value;
    
    var label = "<Whir:Slide";
    
    label += " ID=\""+Id+"\"";
    label += " Width=\""+Width+"\"";
    label += " Height=\""+Height+"\"";
    label += " TextHeight=\""+TextHeight+"\"";
    label += " JsUrl=\""+JsUrl+"\"";
    label += " Top=\""+Top+"\"";
    label += " Select=\""+Select+"\"";
    label += " From=\""+From.split('|')[1]+"\"";
    label += " Where=\""+Where+"\"";
    label += " Order=\""+Order+"\"";
    
    label += " FormID=\""+FormID.split('_')[0]+"\"";
    
    label += ">\n";
    label += Content;
    label += "\n</Whir:Slide>";
    
    return label;
}

function checkForm()
{
    var txtID = document.getElementById("txtID");
    if(txtID.value.replace(/[ ]/g,'') == '')
    {
        alert("请输入ID!");
        txtID.focus();
        return false;
    }
    
    var txtWidth = document.getElementById("txtWidth");
    if(txtWidth.value.search(/^\d+$/) == -1)
    {
        alert("请输入宽度[数字]!");
        txtWidth.focus();
        return false;
    }
    
    var txtHeight = document.getElementById("txtHeight");
    if(txtHeight.value.search(/^\d+$/) == -1)
    {
        alert("请输入高度[数字]!");
        txtHeight.focus();
        return false;
    }
    
    var txtTextHeight = document.getElementById("txtTextHeight");
    if(txtTextHeight.value.search(/^\d+$/) == -1)
    {
        alert("请输入文本高度[数字]!");
        txtTextHeight.focus();
        return false;
    }
    
    var txtJsUrl = document.getElementById("txtJsUrl");
    if(txtJsUrl.value.replace(/[ ]/g,'') == '')
    {
        alert("请输入Js路径!");
        txtJsUrl.focus();
        return false;
    }
    
    var ddlModel = document.getElementById("fs1$ddlModel");
    if(ddlModel.value == '-1')
    {
        alert("请选择数据功能模块!");
        ddlModel.focus();
        return false;
    }
    
    var ddlForm = document.getElementById("fs1$ddlForm");
    if(ddlForm == null || ddlForm.value == '-1')
    {
        alert("请选择数据表单!");
        ddlForm.focus();
        return false;
    }
    
    var txtTop = document.getElementById("txtTop");
    if(txtTop.value.search(/^\d+$/) == -1)
    {
        alert("请输入数据条数[数字]!");
        txtTop.focus();
        return false;
    }
    
    var txtContent = document.getElementById("txtContent");
    if(txtContent.value.replace(/[ ]/g,'') == '')
    {
        alert("请输入显示内容!");
        txtContent.focus();
        return false;
    }
    
    return true;
}
</script>

<script language="javascript" src="../../Js/common.js"></script>

<script type="text/javascript">initAutoFormStyle();</script>

